package com.mx.zb.md.tenant;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;


@EnableFeignClients
//断路器启用，开启Feign后可以不用了
//@EnableCircuitBreaker
//注册为eureka客户端并获得发现服务,ribbon不需要专门注解开启
@EnableDiscoveryClient
@SpringBootApplication
//注意，默认只扫描当前启动类的所在包及子包
@ComponentScan(basePackages= {"com.mx.zb.md.base.service"})
public class MdTenantServiceApplication {	
	
	private final static Logger log = LoggerFactory.getLogger(MdTenantServiceApplication.class); 
	
	@Bean
	@LoadBalanced
	RestTemplate restTemplate() {
		return new RestTemplate();
	}

	public static void main(String[] args) {
		ApplicationContext ctx = SpringApplication.run(MdTenantServiceApplication.class, args);
		
		RestTemplate rest = ctx.getBean(RestTemplate.class);
		Map postData = new HashMap();  
    	
        postData.put("name", "adfds");
        postData.put("age", 42);
		
        //注意，HOST默认会当作服务名来查找，所以不能这样访问
        log.info(rest.postForEntity("http://127.0.0.1:8084/hello", postData, String.class).getBody());
	}
}
